﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace text.Tree
{
    public class _257
    {
        public IList<string> BinaryTreePaths(TreeNode root)
        {
            List<string> res = new List<string>();
            binaryTreePaths(root, "", res);
            return res;
        }
        public void binaryTreePaths(TreeNode root, string path, List<string> res)
        {
            if (root!=null)
            {
                StringBuilder str = new StringBuilder(path);
                str.Append(root.val);
                if (root.left == null && root.right == null)
                {
                    res.Add(str.ToString());
                }
                else
                {
                    str.Append("->");
                    binaryTreePaths(root.left, str.ToString(), res);
                    binaryTreePaths(root.right, str.ToString(), res);
                }
            }
        }
    }
}
